/*
 * 品牌列表
 * @Author: yudong
 * @Date: 2018-04-19 17:53:05
 * @Last Modified by: ljb
 * @Last Modified time: 2019-04-15 17:59:44
 */
<template>
	<div class="v-customer-product-brand-index">

		<Table
			:columns="columns"
			:loading="loading"
			:data="brands"
			:height="tableHeight()"
			border
			class="personal-scrollbar"
			@on-sort-change="sortable"/>

	</div>
</template>

<script>

import Button from 'iview/src/components/button';
import { computedTableHeight } from 'src/views/mixins/computedTableHeight';

export default {
	name: 'BrandIndex',
	mixins: [computedTableHeight],
	props: {
		loading: {
			type: Boolean,
			default() {
				return false;
			},
		},
		brands: {
			type: Array,
			default() {
				return [];
			},
		},
	},
	data() {
		return {
			columns: [
				{
					title: this.$t('brand.name'),
					key: 'name',
					align: 'center',
					render: (h, { row }) => <div> { row.name || '-' } </div>,
				},
				// {
				// 	title: this.$t('brand.url'), // '品牌网址',
				// 	key: 'url',
				// 	align: 'center',
				// 	render: (h, { row }) => <div> { row.url || '-' } </div>,
				// },
				{
					title: this.$t('brand.logo'), // '封面图',
					key: 'logo',
					align: 'center',
					render: (h, { row }) => <div>
						{
							row.logo
								? <img src={ row.logo } alt={this.$t('common.none')} width="50%"/>
								: this.$t('common.none')
						}
					</div>,
				},
				{
					title: this.$t('common.sort'),	// 排序
					key: 'sort',
					align: 'center',
					sortable: 'custom',
					render: (h, { row }) => <div> { row.sort} </div>,
				},
				{
					title: this.$t('common.created_at'), //  '创建时间',
					key: 'created_at',
					align: 'center',
					render: (h, { row }) => <div> { !row.created_at ? '-' : row.created_at } </div>,
				},
				{
					title: this.$t('common.operation'), // '操作',
					align: 'center',
					render: (h, { row }) => (
						<div>
							<Button size="small" style={{ marginRight: '5px' }} on-click={() => { this.$emit('edit', row); }} type="primary">
								{this.$t('common.edit')}
							</Button>
							<Button size="small" on-click={() => { this.$emit('delete', row.id); }} type="error">
								{this.$t('common.delete')}
							</Button>
						</div>),
				},
			],
		};
	},
	methods: {

		/**
         * 排序的回调
         * @param  {Object} param {对应列的属性对象,里面包含了column列属性，key值，order排序字段}
         * @return {undefined}
         */
		sortable(param) {
			const search_param = {

				sort_column: param.order === 'normal' ? '' : param.key,

				sort_by: param.order === 'normal' ? '' : param.order.toLocaleUpperCase(),

			};
			console.log(search_param);
			this.$emit('sort', search_param);
		},

	},
};
</script>
